package llvmir.value.structure;

import java.util.ArrayList;
import java.util.List;

import llvmir.type.Type;
import llvmir.value.User;
import mips.value.Register;

// 指令基类
public abstract class Instruction extends User {
    protected Function parent;
    BasicBlock basicBlock;

    public List<Register> readRegisters = new ArrayList<>(); // 读取的寄存器
    public List<Register> writeRegisters = new ArrayList<>(); // 写入的寄存器

    public Instruction(String name, Type type, BasicBlock basicBlock) {
        super(name, type);
        this.basicBlock = basicBlock;
        this.parent = basicBlock.getParent();
    }

    public Function getParent() {
        return parent;
    }

    public BasicBlock getBasicBlock() {
        return basicBlock;
    }

    public void addReadRef(Register register) {
        readRegisters.add(register);
    }

    public void addWriteRef(Register register) {
        writeRegisters.add(register);
    }

    public List<Register> getReadRegisters() {
        return readRegisters;
    }

    public List<Register> getWriteRegisters() {
        return writeRegisters;
    }
}
